<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Gmap
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
class Gmap_Form_Signup_Location extends Engine_Form
{
  public $invalid_emails = array();
  public $already_members = array();
  public $emails_sent = 0;

  public $session_user;
  
  public function init()
  {
    $this
      ->setAttrib('enctype', 'multipart/form-data')
      ->setAttrib('id', 'SignupForm');


    // Init settings object
    $settings = Engine_Api::_()->getApi('settings', 'core');
    $translate = Zend_Registry::get('Zend_Translate');

    // Init form
    $this
      ->setTitle('Your Map Location')
      ->setDescription('Provide us with your primary location for mapping.')
      ->setLegend('');
    
    $this->addElement('Text', 'title', array(
      'label' => 'Title',
      'description' => 'Enter name of this location. Example: Sweet Home',
      'allowEmpty' => false,
      'required' => true,
      'validators' => array(
        array('NotEmpty', true),
        array('StringLength', false, array(1, 64)),
      ),
      'filters' => array(
        'StripTags',
        new Engine_Filter_Censor(),
      ),
    ));
    $this->title->getDecorator("Description")->setOption("placement", "append");

      $this->addElement('Text', 'location', array(
      'label' => 'Location Address',
      'description' => 'Example: 123 S Main St, Los Angeles, CA 90012',
      'allowEmpty' => false,
      'required' => true,
      'validators' => array(
        array('NotEmpty', true),
        array('StringLength', false, array(1, 255)),
        new Radcodes_Lib_Validate_Location_Address(),
      ),
      'filters' => array(
        'StripTags'
      ),
    ));       
    $this->location->getDecorator("Description")->setOption("placement", "append");
    
    $this->addElement('Textarea', 'description', array(
      'label' => 'Description',
      'description' => 'Maximum: 500 characters',
      'validators' => array(
        array('NotEmpty', true),
        array('StringLength', false, array(1, 500)),
      ),
      'filters' => array(
        'StripTags',
        new Engine_Filter_Censor(),
        new Engine_Filter_HtmlSpecialChars(),
        new Engine_Filter_EnableLinks(),
      ),
    ));  
    $this->description->getDecorator("Description")->setOption("placement", "append");
    
    //$allowed_upload = Engine_Api::_()->authorization()->getPermission($user_level, 'gmap', 'photo');
    //$is_mobile = preg_match("/iphone|ipod|ipad|android|webos/i", strtolower($_SERVER['HTTP_USER_AGENT']));
    $allowed_upload = 1;
    if($allowed_upload){
      $this->addElement('File', 'photo', array(
        'label' => 'Main Photo'
      ));
      $this->photo->addValidator('Extension', false, 'jpg,png,gif');
    }
    
    // prepare categories
    $categories = Engine_Api::_()->gmap()->getCategories();
    if (count($categories)!=0){
      $categories_prepared = Engine_Api::_()->gmap()->convertCategoriesToArray($categories);
      $categories_prepared = array(""=>"") + $categories_prepared;
      
      // category field
      $this->addElement('Select', 'category_id', array(
            'label' => 'Category',
            'multiOptions' => $categories_prepared,
			      'allowEmpty' => false,
			      'required' => true,
			      'validators' => array(
			        array('NotEmpty', true),
			      ),
			      'filters' => array(
			       'Int'
			      ),
          ));
    }    
    
    $this->addElement('Hidden', 'nextStep', array(
      'order' => 3
    ));

    $this->addElement('Hidden', 'skip', array(
      'order' => 4
    ));

    // Element: done
    $this->addElement('Button', 'done', array(
      'label' => 'Create Location',
      'type' => 'submit',
      'onclick' => 'javascript:finishForm();',
      'decorators' => array(
        'ViewHelper',
      ),
    ));

    // Element: skip
    $this->addElement('Cancel', 'skip-link', array(
      'label' => 'skip',
      'prependText' => ' or ',
      'link' => true,
      'href' => 'javascript:void(0);',
      'onclick' => 'skipForm(); return false;',
      'decorators' => array(
        'ViewHelper',
      ),
    ));

    // DisplayGroup: buttons
    $this->addDisplayGroup(array('done', 'skip-link'), 'buttons', array(

    ));
  }

}
